package com.company.controller;

import com.company.domain.Student;
import com.company.service.StudentService;
import com.company.service.StudentServiceImpl;
import org.junit.Test;

import java.security.spec.RSAOtherPrimeInfo;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class studentController {
    private StudentService service = new StudentServiceImpl();

    @Test
    public void FindAll(){
        ArrayList<Student> stuList = service.findAll();
        for (Student student : stuList) {
            System.out.println(student);
        }
    }

    @Test
    public void findById(){
        Student stu = service.findById(8);
        System.out.println(stu);
    }

    @Test
    public void Insert(){
        Student stu = new Student(7, "周七", 20, new Date());
        int update = service.insert(stu);
        if (update == 1){
            System.out.println("上传成功");
        }
    }

    @Test
    public void Update(){
        Student stu = service.findById(8);
        stu.setName("吴妍珠");
        int update = service.update(stu);
        if (update == 1){
            System.out.println("求改成功");
        }
    }

    @Test
    public void Delete(){
        for (int i = 7; i <= 9; i++) {
            int delete = service.delete(i);
        }

    }

    @Test
    public void insertAll() throws SQLException {
        Student stu = new Student(7, "周七", 20, new Date());
        Student stu1 = new Student(8, "周八", 22, new Date());
        Student stu2 = new Student(9, "周八", 24, new Date());
        List<Student> stuList = new ArrayList<>();
        stuList.add(stu);
        stuList.add(stu1);
        stuList.add(stu2);
        service.insertALL(stuList);
    }
}
